package com.feibi.firstplugin.Action;

import com.feibi.firstplugin.Global;
import com.intellij.ide.DataManager;
import com.intellij.openapi.actionSystem.*;
import com.intellij.openapi.vfs.VirtualFile;

public class TransferAction extends AnAction {

    @Override
    public void actionPerformed(AnActionEvent e) {
        ActionManager actionManager = ActionManager.getInstance();
        AnAction action = actionManager.getAction("ProjectViewPopupMenu");
        AnActionEvent event = new AnActionEvent(null, DataManager.getInstance().getDataContext(),
                ActionPlaces.UNKNOWN, new Presentation(), actionManager, 0);
        action.update(event);
        VirtualFile[] virtualFiles = event.getData(PlatformDataKeys.VIRTUAL_FILE_ARRAY);
        if (virtualFiles != null && virtualFiles.length > 0) {
            VirtualFile virtualFile = virtualFiles[0];
            String path = virtualFile.getPath();
            if (virtualFile.isDirectory()) {
                System.out.println("selected directory: " + path);
            }else {
                System.out.println("selected file: " + path);
            }
            Global.project = e.getProject();
            InputJsonDialog inputJsonDialog = new InputJsonDialog(e.getProject(),virtualFile);
            inputJsonDialog.show();
        }

    }


}
